package com.zhiyueshufang.activity

import android.content.Intent
import android.os.Bundle
import android.view.KeyEvent
import com.zhiyueshufang.R
import java.util.Timer
import java.util.TimerTask

class SplashActivity : BaseActivity() {

    /**
     * 定时器
     */
    private lateinit var count_down_timer: Timer

    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        setContentView(R.layout.activity_splash)

        /**
         * 跳转到首页
         */
        jump_to_home_page()
    }

    /**
     * 返回事件
     */
    override fun onBackPressed() {
        count_down_timer?.cancel()
        this.finish()
    }

    override fun onKeyDown(keyCode: Int, event: KeyEvent?): Boolean {
        if (keyCode == KeyEvent.KEYCODE_HOME) {
            onBackPressed()
            return true
        }
        return super.onKeyDown(keyCode, event)
    }

    /**
     * 跳转到首页
     */
    fun jump_to_home_page() {

        var current_activity = this

        count_down_timer = Timer()

        class jump_time_task() : TimerTask() {
            override fun run() {
                val home_activity_intent = Intent(current_activity, HomeActivity::class.java)
                startActivity(home_activity_intent)
                current_activity.finish()
            }
        }
        count_down_timer.schedule(jump_time_task(), 500)
    }
}